<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>防抖演示1</div>
    <div>防抖演示2</div>
    <div>防抖演示3</div>
    <div>防抖演示4</div>
    <div>防抖演示5</div>
    <div>防抖演示6</div>
    <div>防抖演示7</div>
    <div>防抖演示8</div>
    <div>防抖演示9</div>
    <div>防抖演示10</div>
    <div>防抖演示11</div>
    <div>防抖演示12</div>
    <div>防抖演示13</div>
    <div>防抖演示14</div>
    <div>防抖演示15</div>
    <div>防抖演示16</div>
    <div>防抖演示17</div>
    <div>防抖演示18</div>
    <div>防抖演示19</div>
    <div>防抖演示20</div>
    <div>防抖演示21</div>
    <div>防抖演示22</div>
    <div>防抖演示23</div>
    <div>防抖演示24</div>
    <div>防抖演示25</div>
    <div>防抖演示26</div>
    <div>防抖演示27</div>
    <div>防抖演示28</div>
    <div>防抖演示29</div>
    <div>防抖演示30</div>
    <div>防抖演示31</div>
    <div>防抖演示32</div>
    <div>防抖演示33</div>
    <div>防抖演示34</div>
    <div>防抖演示35</div>
    <script>
        var throttle = function (func, delay) {
            var timer = null;
            var startTime = Date.now();
            return function () {
                var curTime = Date.now();
                var remaining = delay - (curTime - startTime);
                var context = this;
                var args = arguments;
                clearTimeout(timer);
                if (remaining <= 0) {
                    func.apply(context, args);
                    startTime = Date.now();
                } else {
                    timer = setTimeout(func, remaining);
                }
            }
        }

        function handle() {
            console.log(Math.random());
        }
        window.addEventListener('scroll', throttle(handle, 1000));
    </script>
</body>
</html>